package work20241226;

import sun.font.FontRunIterator;

/**
 * @author zdl
 * @date 2024/12/26
 */
public class Demo7 {
    public static void main(String[] args) {
        //7. 创建两个线程循环1000次打印，其中一个线程礼让另一个线程，观察输出结果。
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println(Thread.currentThread().getName()+"线程:"+i);
                    if (i % 10 == 0){
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println(Thread.currentThread().getName()+"线程:"+i);
                    /*if (i % 10 == 0){
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }*/
                }
            }
        }).start();
    }
}
